home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / double.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  4KB  |  136 lines

  1.  
  2.  
  3.     /***********************************************
  4.     *
  5.     *   file d:\cips\double.c
  6.     *
  7.     *   Functions: This file contains
  8.     *      main
  9.     *
  10.     *   Purpose:
  11.     *      This file contains the main calling
  12.     *      routine for a program which enlarges
  13.     *      an image by a factor of two using the
  14.     *      replication method.
  15.     *
  16.     *   External Calls:
  17.     *      gin.c - get_image_name
  18.     *      numcvrt.c - get_integer
  19.     *                  int_convert
  20.     *      tiff.c - read_tiff_header
  21.     *
  22.     *   Modifications:
  23.     *      7 November 1992 - created
  24.     *
  25.     *************************************************/
  26.  
  27. #include "cips.h"
  28.  
  29.  
  30.  
  31. short the_image[ROWS][COLS];
  32. short out_image[ROWS][COLS];
  33.  
  34. main(argc, argv)
  35.    int argc;
  36.    char *argv[];
  37. {
  38.  
  39.    char     method[80], in_name[80], out_name[80];
  40.    int      a, A, b, B, count, count1, factor,
  41.             i, I, j, J, length, width,
  42.             il, ie, ll, le;
  43.    struct   tiff_header_struct image_header;
  44.  
  45.    my_clear_text_screen();
  46.  
  47.        /******************************************
  48.        *
  49.        *  Interpret the command line parameters.
  50.        *
  51.        *******************************************/
  52.  
  53.    if(argc < 3 || argc > 3){
  54.     printf(
  55.      "\n"
  56.      "\n usage: double in-file out-file"
  57.      "\n        This program doubles (enlarges)"
  58.      "\n        the in-file using replication."
  59.      "\n");
  60.     exit(0);
  61.    }
  62.  
  63.    strcpy(in_name,   argv[1]);
  64.    strcpy(out_name,  argv[2]);
  65.  
  66.    il = 1;
  67.    ie = 1;
  68.    ll = ROWS+1;
  69.    le = COLS+1;
  70.    factor = 2;
  71.  
  72.        /********************************************
  73.        *
  74.        *   Read the input image header and setup
  75.        *   the looping counters.
  76.        *
  77.        *   Create the output image.
  78.        *
  79.        ********************************************/
  80.  
  81.    read_tiff_header(in_name, &image_header);
  82.  
  83.    length = (ROWS-10 + image_header.image_length)/ROWS;
  84.    width  = (COLS-10 + image_header.image_width)/COLS;
  85.    count  = 1;
  86.    count1 = 1;
  87.  
  88.    image_header.image_length = length*ROWS*2;
  89.    image_header.image_width  = width*COLS*2;
  90.    create_allocate_tiff_file(out_name, &image_header,
  91.                              out_image);
  92.  
  93.        /********************************************
  94.        *
  95.        *   Read and double each 100x100 area of the
  96.        *   input image and write them to the output
  97.        *   image.
  98.        *
  99.        **********************************************/
  100.  
  101.    count = 1;
  102.    for(I=0; I<length; I++){
  103.       for(J=0; J<width; J++){
  104.          printf("\nrunning %d of %d", 
  105.                 count1++, length*width);
  106.  
  107.          read_tiff_image(in_name, the_image, 
  108.                          il+I*ROWS, ie+J*COLS, 
  109.                          ll+I*ROWS, le+J*COLS);
  110.          count = 1;
  111.          for(A=0; A<factor; A++){
  112.           for(B=0; B<factor; B++){
  113.            for(i=0; i<ROWS/factor; i++){
  114.             for(j=0; j<COLS/factor; j++){
  115.              for(a=0; a<factor; a++){
  116.               for(b=0; b<factor; b++){
  117.                out_image[factor*i+a][factor*j+b] =
  118.                the_image[i+A*ROWS/factor][j+B*COLS/factor];
  119.               }  /* ends loop over b */
  120.              }  /* ends loop over a */
  121.             }  /* ends loop over j */
  122.            }  /* ends loop over i */
  123.            printf("\n\tzooming replication %3d of %3d",
  124.                   count++, factor*factor);
  125.            write_array_into_tiff_image(out_name, 
  126.                out_image, 1+A*ROWS+I*ROWS*factor, 
  127.                1+B*COLS+J*COLS*factor, 
  128.                101+A*ROWS+I*ROWS*factor, 
  129.                101+B*COLS+J*COLS*factor);
  130.           }  /* ends loop over B */
  131.          }  /* ends loop over A */
  132.  
  133.       }  /* ends loop over J */
  134.    }  /* ends loop over I */
  135. }  /* ends main  */
  136.